Hi,
I'm trying to pass a parameter via a function pointer. My first attempt without a parameter works but when adding it, it fails.
So this is without an in parameter to the function pointer in checkPin():
Code:
#include <stdio.h>
void sayHello(void)
{
printf("Hello\n");
}
void checkPin(const int pin, void (*response)(void))
{
if (pin == 0)
{
response();
}
}
int main()
{
checkPin(0, sayHello);
return 0;
}
And here I've added an int to the function:
Code:
#include <stdlib.h>
void sayHello(int a)
{
printf("Hello\n");
}
void checkPin(const int pin, void (*response)(int a))
{
int a;
if (pin == 0)
{
response(a);
}
}
int main()
{
checkPin(0, sayHello(10));
return 0;
}
I get a compile error pointing at the row checkPin(0, sayHello(10));
error: invalid use of void expression
And probably how to get the parameter information in checkPin() to response().